package be.redo.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import be.redo.dao.FlightDAO;
import be.redo.model.entities.AirlineCompany;
import be.redo.model.entities.Flight;
import be.redo.model.entities.Line;

@Service
@Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED)
public class FlightServiceImpl implements FlightService {

	@Autowired
	FlightDAO dao;

	@Override
	@Transactional(readOnly = false)
	public void create(Flight instance) {
		dao.create(instance);
	}

	@Override
	public Flight read(long id) {
		return dao.read(id);
	}

	@Override
	@Transactional(readOnly = false)
	public void update(Flight instance) {
		dao.update(instance);
	}

	@Override
	@Transactional(readOnly = false)
	public void delete(long id) {
		dao.delete(id);
	}

	@Override
	public List<Flight> findAll() {
		return dao.findAll();
	}

	@Override
	public int count() {
		return dao.count();
	}

	@Override
	public List<Flight> findFlightsByAirlineCompany(
			AirlineCompany airlineCompany) {
		return dao.findFlightsByAirlineCompany(airlineCompany);
	}

	@Override
	public List<Flight> findFlightsByDepartureTimeBetween(Date lowerTime,
			Date higherTime) {
		return dao.findFlightsByDepartureTimeBetween(lowerTime, higherTime);
	}

	@Override
	public List<Flight> findFlightsByDepartureTimeEquals(Date departureTime) {
		return dao.findFlightsByDepartureTimeEquals(departureTime);
	}

	@Override
	public List<Flight> findFlightsByLine(Line line) {
		return dao.findFlightsByLine(line);
	}

	@Override
	public List<Flight> findFlightsByFlightCodeLike(String flightCode) {
		return dao.findFlightsByFlightCodeLike(flightCode);
	}

	@Override
	public List<Flight> findFlightsByLineWhereDepartureIsLaterThan(Line line,
			Date time) {
		return dao.findFlightsByLineWhereDepartureIsLaterThan(line, time);
	}
}
